package com.example.pclimb.viewmodel;

import android.app.Application;

import androidx.annotation.NonNull;
import androidx.lifecycle.AndroidViewModel;
import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;

import com.example.pclimb.model.Review;
import com.example.pclimb.repository.ReviewRepository;
import com.example.pclimb.repository.UserRepository;

import java.util.List;

/**
 * 评价视图模型，负责处理评价相关的UI数据
 */
public class ReviewViewModel extends AndroidViewModel {
    private ReviewRepository repository;
    private MutableLiveData<Review> selectedReview = new MutableLiveData<>();

    public ReviewViewModel(@NonNull Application application) {
        super(application);
        repository = new ReviewRepository(application);
    }

    public void insert(Review review, UserRepository.Callback<Long> callback) {
        repository.insert(review, callback);
    }

    public void update(Review review) {
        repository.update(review);
    }

    public void delete(Review review) {
        repository.delete(review);
    }

    public LiveData<Review> getReviewById(int reviewId) {
        return repository.getReviewById(reviewId);
    }

    public LiveData<List<Review>> getReviewsByUser(int userId) {
        return repository.getReviewsByUser(userId);
    }

    public LiveData<List<Review>> getReviewsByGuide(int guideId) {
        return repository.getReviewsByGuide(guideId);
    }

    public LiveData<Review> getReviewByRequest(int requestId) {
        return repository.getReviewByRequest(requestId);
    }

    public LiveData<Float> getAverageRatingForGuide(int guideId) {
        return repository.getAverageRatingForGuide(guideId);
    }

    public LiveData<Integer> getReviewCountForGuide(int guideId) {
        return repository.getReviewCountForGuide(guideId);
    }

    public void setSelectedReview(Review review) {
        selectedReview.setValue(review);
    }

    public LiveData<Review> getSelectedReview() {
        return selectedReview;
    }
} 